﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;

namespace Hi_Baidu.Net
{
    public class SystemUdpMessageListener : MessageListener
    {
        
        public SystemUdpMessageListener(int ReadLength)
            : base(ReadLength)
        {
            
        }

        private UdpClient udpclient;
        public UdpClient Udpclient
        {
            get { return udpclient; }
            set { udpclient = value; }
        }

        protected override void Listen()
        {
            IPEndPoint IEP = null;
           while(this.IS_LOOP_GET_MESSAGE)
           {
               byte[] Content = Udpclient.Receive(ref IEP);
               //打入信息池
               this.NetworkMessagePool.Write(Content, Content.Length);
           }
        }

        public override void Init()
        {
            //创建监听线程
            this.CurrentThread = new Thread(new ThreadStart(this.Listen));
            CurrentThread.Name = "Listener Message of UDP Port";
            CurrentThread.Start();
        }

        public override void Dispose()
        {
            throw new NotImplementedException();
        }
    }
}
